package cn.wonderland.base.dto;

import cn.wonderland.base.util.MD5Utils;
import cn.wonderland.base.util.StrUtils;
import cn.wonderland.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 手机号注册dto
 */
@Data
public class EmailRegisterDto {

    // 手机号
    @NotBlank(message = "邮箱账号不能为空！")
    private String email;
    @NotBlank(message = "二次密码不能为空！")
    private String passwordRepeat;
    @NotBlank(message = "密码不能为空！")
    private String password;
    @NotBlank(message = "验证码不能为空！")
    private String emailCode;

    public User getUser(){
        String salt = StrUtils.getComplexRandomString(32);
        // 密码 盐值+密码 加密
        String password = MD5Utils.encrypByMd5(salt + this.getPassword());
        return User.builder()
                .username(this.email)
                .email(this.email)
                .salt(salt)
                .password(password)
                .state(1)
                .createtime(new Date())
                .build();
    }

}